<?php
// +----------------------------------------------------------------------
// | webhooks
// +----------------------------------------------------------------------
// | Author: King east <1207877378@qq.com>
// +----------------------------------------------------------------------


namespace app\common\model;


use think\facade\Cache;
use think\facade\Cookie;
use think\Model;

class Admin extends Model
{
    public function hasPassword($pass)
    {
        return password_verify($pass, $this->getData('password'));
    }

    public function login()
    {
        $admin = $this->getData();
        $token = strtoupper(md5($admin->username . mt_rand(0, 999999) . $_SERVER['REQUEST_TIME']));
        Cache::set('admin_token_' . $token, $admin->toArray(), 7200);
        Cookie::set('admin_token', $token, 7200);
    }

}